import {getDocsListApi,getKbsListApi,uploadFileApi,uploadFilesApi,localDocChatApi} from "@/api/kbs"

const state = {
    name: '',
    role: ''
}

const mutations = {
    SET_NAME: (state, name) => {
        state.name = name
    },
    SET_ROLE: (state, role) => {
        state.role = role
    }
}

const actions = {
    // user login
    getDocsList({ commit }, data) {
        console.log('kbs/getDocsListApi', data)
        return new Promise((resolve, reject) => {
          getDocsListApi(data).then(res => {
              console.log('getDocsList', res);
              if (res.status === 200) {
                resolve({
                    type: "success",
                    message: res.msg
                })
            } else {
                reject({
                    type: "error",
                    message: res.msg
                })
            }
        }).catch(error => {
            reject({
                type: "error",
                message: error.msg
            })
        })
    },  
        )
  },
  getKbsList({ commit }, data) {
    console.log('kbs/getKbsList', data)
    return new Promise((resolve, reject) => {
      getKbsListApi(data).then(res => {
          console.log('getKbsList', res);
          if (res.status === 200) {
            resolve({
                type: "success",
                message: res.msg
            })
        } else {
            reject({
                type: "error",
                message: res.msg
            })
        }
    }).catch(error => {
        reject({
            type: "error",
            message: error.msg
        })
    })
   },  
  )},

 uploadFile({ commit }, data) {
    console.log('kbs/uploadFile', data)
    return new Promise((resolve, reject) => {
        uploadFileApi(data).then(res => {
          console.log('uploadFile', res);
          if (res.status === 200) {
            resolve({
                type: "success",
                message: res.msg
            })
        } else {
            reject({
                type: "error",
                message: res.msg
            })
        }
    }).catch(error => {
        reject({
            type: "error",
            message: error.msg
        })
    })
},  
    )
},

uploadFiles({ commit }, data) {
    console.log('kbs/uploadFiles', data)
    return new Promise((resolve, reject) => {
        uploadFilesApi(data).then(res => {
          console.log('uploadFile', res);
          if (res.status === 200) {
            resolve({
                type: "success",
                message: res.msg
            })
        } else {
            reject({
                type: "error",
                message: res.msg
            })
        }
    }).catch(error => {
        reject({
            type: "error",
            message: error.msg
        })
    })
},  
    )
},

localDocChat({ commit }, data) {
    console.log('kbs/localDocChat', data)
    return new Promise((resolve, reject) => {
        localDocChatApi(data).then(res => {
          console.log('localDocChat', res);
          if (res.status === 200) {
            resolve({
                type: "success",
                message: res.msg
            })
        } else {
            reject({
                type: "error",
                message: res.msg
            })
        }
    }).catch(error => {
        reject({
            type: "error",
            message: error.msg
        })
    })
},  
    )
}

}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
